// ==UserScript==
// @name         sl-zhlx
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  隐藏指定网站上的质检结论相关元素
// @author       You
// @match        https://web-cdn.zhonghuilife.com/*
// @grant        none
// @updateURL    https://gitee.com/i-recruit-handsome/i-attract-good-fortune/raw/master/sl-zhlx.user.js
// @downloadURL  https://gitee.com/i-recruit-handsome/i-attract-good-fortune/raw/master/sl-zhlx.user.js
// ==/UserScript==

(function() {
    'use strict';

    // 等待页面加载完成
    function hideElements() {
        // 清空结论按钮内容（保留表头）
        const conclusionButtons = document.querySelectorAll('tbody td[data-field="zhengtiverdict"][lay-event="switchConclusion"]');
        conclusionButtons.forEach(button => {
            const cell = button.querySelector('.layui-table-cell');
            if (cell) {
                cell.innerHTML = '';
            }
        });

        // 清空备注字段内容（保留表头）
        const remarkFields = document.querySelectorAll('tbody td[data-field="issuedesc"]');
        remarkFields.forEach(field => {
            const cell = field.querySelector('.layui-table-cell');
            if (cell) {
                cell.innerHTML = '';
            }
        });

        // 清空质检相关的td字段内容（保留表头）
        const qcFields = [
            'tbody td[data-field="firstQcMainRemarks"]',
            'tbody td[data-field="qcMainRemarks"]',
            'tbody td[data-field="firstVerdict"]'
        ];
        qcFields.forEach(selector => {
            const elements = document.querySelectorAll(selector);
            elements.forEach(element => {
                const cell = element.querySelector('.layui-table-cell');
                if (cell) {
                    cell.innerHTML = '';
                }
            });
        });

        // 隐藏质检结论下发表单
        const qcForm = document.querySelector('form.layui-form');
        if (qcForm) {
            // 检查表单是否包含质检结论相关内容
            const finalQcVerdict = qcForm.querySelector('#finalQcVerdict');
            const qcResultSubmitBtn = qcForm.querySelector('#qc_result_submit_btn');
            
            if (finalQcVerdict || qcResultSubmitBtn) {
                qcForm.style.display = 'none';
            }
        }

        // 清空包含审核结论文本的div元素内容（优化性能）
        const auditTexts = ['审核通过', '审核不通过', '通过', '不通过', '合格', '不合格'];
        auditTexts.forEach(text => {
            const xpath = `//div[normalize-space(text())='${text}']`;
            const result = document.evaluate(xpath, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
            for (let i = 0; i < result.snapshotLength; i++) {
                const div = result.snapshotItem(i);
                if (div && div.textContent.trim() === text) {
                    div.textContent = '';
                }
            }
        });

        // 也可以通过CSS选择器更精确地隐藏
        const style = document.createElement('style');
        style.textContent = `
            /* 清空结论按钮内容（只针对tbody，保留表头） */
            tbody td[data-field="zhengtiverdict"][lay-event="switchConclusion"] .layui-table-cell {
                color: transparent !important;
            }
            
            /* 清空备注字段内容（只针对tbody，保留表头） */
            tbody td[data-field="issuedesc"] .layui-table-cell {
                color: transparent !important;
            }
            
            /* 清空质检相关的td字段内容（只针对tbody，保留表头） */
            tbody td[data-field="firstQcMainRemarks"] .layui-table-cell,
            tbody td[data-field="qcMainRemarks"] .layui-table-cell,
            tbody td[data-field="firstVerdict"] .layui-table-cell {
                color: transparent !important;
            }
            
            /* 隐藏包含质检结论的表单 */
            form.layui-form:has(#finalQcVerdict),
            form.layui-form:has(#qc_result_submit_btn) {
                display: none !important;
            }
            
            /* 备用方案：直接通过ID隐藏 */
            #finalQcVerdict,
            #qcVerdictDesc,
            #qc_result_submit_btn {
                display: none !important;
            }
            
            /* 清空包含审核结论文本的div元素 */
            div:contains("审核通过"),
            div:contains("审核不通过"),
            div:contains("通过"),
            div:contains("不通过"),
            div:contains("合格"),
            div:contains("不合格") {
                color: transparent !important;
            }
        `;
        document.head.appendChild(style);
    }

    // 页面加载完成后执行
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', hideElements);
    } else {
        hideElements();
    }

    // 监听动态内容变化（添加防护机制）
    let isProcessing = false;
    const observer = new MutationObserver(function(mutations) {
        if (isProcessing) return;
        
        let shouldProcess = false;
        mutations.forEach(function(mutation) {
            if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
                shouldProcess = true;
            }
        });
        
        if (shouldProcess) {
            isProcessing = true;
            setTimeout(() => {
                hideElements();
                isProcessing = false;
            }, 100);
        }
    });

    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

})();